define("charoite/navigator",
    ["dojo/_base/declare", "dijit/layout/BorderContainer", "dijit/Toolbar", "dijit/form/Button", "dijit/Tree", "dojo/domReady!"],
    function(declare, BorderContainer, Toolbar, Button, Tree) {
        return declare("charoite.navigator", BorderContainer, {

            store : {},
            toolbar : {},
            tree : {},

            constructor : function(options)
            {
                declare.safeMixin(this, options);
            },

            startup : function()
            {
                this.inherited(arguments);
                context = this;

                context.toolbar = new Toolbar({
                    region: "top",
                    "class": "edgePanel",
                    content: "Header content (top)"
                });
                context.toolbar.startup();
                context.addChild(context.toolbar);

                context.tree = new Tree({
                    region: "center",
                    id : "tree",
                    showRoot: false,
                    model: context.store
                });
                context.tree.startup();
                context.addChild(context.tree);

                dojo.forEach(["Cut", "Copy", "Paste"], function(label)
                {
                    var button = new Button({
                        label     : label,
                        showLabel : false,
                        iconClass : "dijitEditorIcon dijitEditorIcon"+label,
                        onClick   : function(){
                            var selectedObject = context.tree.get("selectedItems")[0];
                            if(!selectedObject)
                            {
                                return alert("No object selected");
                            }
                            console.debug(selectedObject);
                            context.store.add({caption : "Новый тест"}, {parent: selectedObject});
                        }
                    });
                    context.toolbar.addChild(button);
                });
            }

        });
    });